﻿using Microsoft.EntityFrameworkCore;
using Production.DomainLib.AggregatesModel.TechnologyAggregate;
using Swimj.DomainLib.SeedWork;

namespace Production.InfrastructureLib.Repositories
{
    public class TechnologyRepository : ITechnologyRepository
    {
        private readonly ProductionDbContext _dbContext;
        public IUnitOfWork UnitOfWork => _dbContext;

        public TechnologyRepository(ProductionDbContext dbContext)
        {
            _dbContext = dbContext;
        }

        public Technology Add(Technology technology)
        {
            return _dbContext.Technologies.Add(technology).Entity;
        }

        public async Task<IList<TechnologyDetail>?> QueryTechnologyDetails(int requestTechnologyId)
        {
            var technology = await _dbContext.Technologies
                 .Include(i => i.TechnologyDetails)
                 .FirstOrDefaultAsync(i => i.Id == requestTechnologyId);

            return technology?.TechnologyDetails.ToList();
        }

        public Task<Technology?> Get(int requestId)
        {
            return _dbContext.Technologies
                .Include(i => i.TechnologyDetails)
                .FirstOrDefaultAsync(i => i.Id == requestId);
        }
    }
}